﻿@using Newtouch.Herp.Infrastructure.Enum;
@using Newtouch.Tools
@{
    ViewBag.Title = "申领单查询";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<style>
    #btn_search {
        width: 45px;
        font-weight: bolder;
    }

    #btn_print {
        width: 45px;
        background-color: #fff;
        color: #00a9ea;
        font-weight: bolder;
    }

    .showbotton {
        display: none;
        position: fixed;
        bottom: 5px;
        right: 0;
        z-index: 9999;
        background-color: #ccc;
        width: 50px;
        height: 44px;
        filter: alpha(Opacity=90);
        -moz-opacity: 0.9;
        opacity: 0.9;
        cursor: pointer;
        border-radius: 100px 0 0 100px;
    }

    #TabGrid {
        width: 100%;
        position: fixed;
        bottom: 10px;
        right: 0;
        z-index: 8888;
        background-color: #253443;
        filter: alpha(Opacity=92);
        -moz-opacity: 0.92;
        opacity: 0.92;
        box-shadow: 0px 2px 10px #909090;
    }

        #TabGrid > * {
            filter: alpha(Opacity=92);
            -moz-opacity: 0.92;
            opacity: 0.92;
        }
</style>
<form id="form1">
    <div class="panel panel-default" id="dv_search">
        <div class="panel-heading">
            查询条件
        </div>
        <div style="padding-right:10px;">
            <table class="form">
                <tr>
                    <th class="formTitle">处理状态：</th>
                    <td class="formValue">
                        @Html.DropDownList("applyProcess", EnumApplyProcess.Waiting.ToDescSelectList(), "全部", new { @class = "form-control" })
                    </td>
                    <th class="formTitle"><span class="required">*</span>提交日期：</th>
                    <td class="formValue">
                        <input id="txtStartDate" type="text" class="form-control input-wdatepicker " value="@DateTime.Now.ToString("yyyy-MM-01 00:00:00")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" />
                    </td>
                    <th class="formTitle"><span class="required">*</span>至：</th>
                    <td class="formValue">
                        <input id="txtEndDate" type="text" class="form-control input-wdatepicker " value="@DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" />
                    </td>
                    <th class="formTitle">单据号：</th>
                    <td class="formValue">
                        <input type="text" class="form-control" id="txtPDH" placeholder="单据号" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">单据类型：</th>
                    <td class="formValue">
                        @Html.DropDownList("applyType", EnumApplyType.DepartmentApply.ToDescSelectList(), "全部", new { @class = "form-control" })
                    </td>
                    <td class="formTitle" colspan="6">
                        <input type="button" id="btn_search" class="btn btn-md btn-primary" value="查询" />
                        <input type="button" id="btn_print" class="btn btn-md btn-primary" value="打印" />
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div class="gridPanel">
        <table id="gridDJMainRecords"></table>
        <div id="gridPager" rel="form1"></div>
    </div>
</form>
<div id="TabGrid">
    <ul class="nav nav-tabs navb-bg" role="tablist" id="myTab">
        <li role="presentation" class="active">
            <a href="#dv_djmx" id="linkSearch" role="tab" data-toggle="tab">单据明细</a>
        </li>
        <li style="float:right">
            <span class="hiding glyphicon glyphicon-chevron-right btn-lg"></span>
        </li>
    </ul>
    <div id="dv_djmx" style="">
        <table id="gridDJMXInfo"></table>
    </div>
</div>
<div class="showbotton">
    <span class="glyphicon glyphicon-chevron-left btn-lg"></span>
</div>

<script>
    var $gridDjMainRecords = $("#gridDJMainRecords");
    $(function () {
        //浏览器窗口调整大小时重新加载jqGrid的宽
        $(window).resize(function () {
            window.initLayout("MyTabGrid");
        });
        //搜索框隐藏显示控制
        $(".hiding,.rows,#dv_search,.toolbar").click(function () {
            TabGridHide();
        });
        $(".showbotton").click(function () {
            $(".showbotton").animate({ width: 'hide' }, "fast", function () {
                $("#TabGrid").animate({ left: '0px' }, "slow");
            });
        });
        TabGridHide();
        gridDJMainRecords();
        $("#btn_print").click(function () {
            var rowIds = $gridDjMainRecords.jqGrid('getRowData_AllLine');
            if (!rowIds|| rowIds.length <= 0) {
                $.newtouchAlert("打印内容不允许为空");
                return;
            }

            //打印全部查询
            var applyProcess = $("#applyProcess").val();
            var applyType = $("#applyType").val();
            var kssj = $("#txtStartDate").val();
            var jssj = $("#txtEndDate").val();
            applyType = applyType == undefined || applyType === "" ? 0 : applyType;
            applyProcess = applyProcess == undefined || applyProcess === "" ? 0 : applyProcess;
            var sldh = $("#txtPDH").val();
            var rowId = $gridDjMainRecords.jqGrid('getGridParam', 'selrow');
            if (rowId) {
                //打印选中
                var rowData = $gridDjMainRecords.jqGrid('getRowData', rowId);
                sldh = rowData.sldh;
            }
            window.open("/Report/PrintReport?type=ApplyBill&param=OrganizeId=@ViewBag.OrganizeId|applyProcess=" + applyProcess
                + "|applyType=" + applyType + "|kssj=" + kssj + "|jssj=" + jssj + "|sldh=" + sldh);
        });
    });

    //回车事件绑定
    $(document).keyup(function (event) {
        if (event.keyCode === 13) {
            $("#btn_search").trigger("click");
        }
    });

    //隐藏搜索框并显示箭头
    function TabGridHide() {
        var tabGridwith = $("#TabGrid").width() + 200;
        if ($(".showbotton").is(":hidden")) {
            $("#TabGrid").animate({ left: tabGridwith }, "slow", function () {
                $(".showbotton").animate({ width: 'show' }, "fast");
            });
        }
    }

    //单据主记录
    function gridDJMainRecords() {
        $gridDjMainRecords.dataGrid({
            postData: getSearchPostData(),
            height: $(window).height() - 185,
            url: "/ApplyBill/ApplyBillInfoQuery",
            colModel: [
                {
                    label: '处理状态', name: 'applyProcess', width: 100, align: 'center', formatter: function (val) {
                        switch (val) {
                        case @((int)EnumApplyProcess.Waiting):
                            return "@EnumApplyProcess.Waiting.GetDescription()";
                        case @((int)EnumApplyProcess.AuditApproved):
                            return "@EnumApplyProcess.AuditApproved.GetDescription()";
                        case @((int)EnumApplyProcess.AuditFailed):
                            return "@EnumApplyProcess.AuditFailed.GetDescription()";
                        case @((int)EnumApplyProcess.Distributing):
                            return "@EnumApplyProcess.Distributing.GetDescription()";
                        case @((int)EnumApplyProcess.PartialCompletion):
                            return "@EnumApplyProcess.PartialCompletion.GetDescription()";
                        case @((int)EnumApplyProcess.Completion):
                            return "@EnumApplyProcess.Completion.GetDescription()";
                        case @((int)EnumApplyProcess.Rejection):
                            return "@EnumApplyProcess.Rejection.GetDescription()";
                        default:
                            return "";
                        }
                    }
                },
                {
                    label: '单据类型', name: 'applyType', width: 100, align: 'center', formatter: function (val) {
                        switch (val) {
                        case @((int)EnumApplyType.DepartmentApply):
                            return "@EnumApplyType.DepartmentApply.GetDescription()";
                        case @((int)EnumApplyType.WarehouseApply):
                            return "@EnumApplyType.WarehouseApply.GetDescription()";
                        default:
                            return "";
                        }
                    }
                },
                { label: '单据号', name: 'sldh', width: 150, align: 'center' },
                { label: '出库库房', name: 'ckbmmc', width: 150, align: 'center' },
                { label: '入库库房', name: 'rkbmmc', width: 150, align: 'center' },
                { label: '入库科室', name: 'rkksmc', width: 150, align: 'center' },
                { label: '创建时间', name: 'CreateTime', width: 120, align: 'center', formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' } },
                { label: '创建人', name: 'CreatorName', width: 90, align: 'center' }
            ],
            unwritten: false,
            multiselect: false,
            pager: "#gridPager",
            sortname: 'CreateTime desc',
            viewrecords: true,
            ondblClickRow: function (rowid, iRow, iCol, e) {
                btn_selectrow(rowid);
            },
            loadComplete: function () {
                $(".ui-jqgrid-bdiv").css("overflow", "auto");
            }
        });

        $("#btn_search").click(function () {
            if ($("#txtStartDate").val() === "") {
                $.modalMsg("请选择开始时间", 'error', 1500);
                return false;
            }
            if ($("#txtEndDate").val() === "") {
                $.modalMsg("请选择结束时间", 'error', 1500);
                return false;
            }
            $('#gridDJMXInfo').jqGrid("clearGridData");
            $gridDjMainRecords.jqGrid('setGridParam', {
                postData: getSearchPostData()
            }).trigger('reloadGrid');
        });
    }

    //组装查询条件
    function getSearchPostData() {
        var applyProcess = $("#applyProcess").val();
        var applyType = $("#applyType").val();
        var kssj = $("#txtStartDate").val();
        var jssj = $("#txtEndDate").val();
        var pdh = $("#txtPDH").val();
        applyType = applyType == undefined || applyType === "" ? 0 : applyType;
        applyProcess = applyProcess == undefined || applyProcess === "" ? 0 : applyProcess;
        return { kssj: kssj, jssj: jssj, pdh: pdh, applyType: applyType, applyProcess: applyProcess };
    };

    //单击事件
    function btn_selectrow(rowId) {
        $('#gridDJMXInfo').jqGrid("clearGridData");//每次单击，先清空明细 再重新加载所有选中行明细
        $.najax({
            type: "Get",
            url: "/ApplyBill/ApplyBillDetailBySldhQuery",
            data: { sldId: $("#gridDJMainRecords").jqGrid('getRowData', rowId).sldh },
            dataType: "json",
            success: function (ajaxresp) {
                if (ajaxresp !== null) {
                    $('#gridDJMXInfo').newtouchLocalDataGrid(null, ajaxresp);
                }
                $(".showbotton").click().trigger("click");
            }
        });
    }

    //单据明细
    $('#gridDJMXInfo').newtouchLocalDataGrid({
        height: $(window).height() - 200,
        unwritten: false,
        sortable: false,
        colModel: [
            { label: '类别', name: 'lbmc', width: 130, align: 'center' },
            { label: '名称', name: 'wzmc', width: 160, align: 'center' },
            { label: '申领数量', name: 'slStr', width: 90, align: 'center' },
            { label: '已发数量', name: 'yfslStr', width: 90, align: 'center' },
            { label: '规格', name: 'gg', width: 120, align: 'center' },
            { label: '品牌', name: 'brand', width: 120, align: 'center' },
            { label: '生产厂家', name: 'sccj', width: 160, align: 'center' }
        ]
    });

</script>